<template>
  <div class="pet-list-container">
    <div class="pet-header">
      <h2>我的宠物</h2>
      <button class="add-pet-btn" @click="$emit('show-shop')">
        <span class="icon">🐾</span>
        领养新宠物
      </button>
    </div>

    <!-- 宠物列表 -->
    <div class="pet-grid">
      <div 
        v-for="pet in pets" 
        :key="pet.id" 
        class="pet-card"
        @click="selectPet(pet)"
      >
        <div class="pet-avatar">
          <span class="pet-icon">{{ getPetIcon(pet.type) }}</span>
          <span class="mood-indicator" :title="pet.mood">{{ getMoodIcon(pet.mood) }}</span>
        </div>
        
        <div class="pet-info">
          <h3>{{ pet.name }}</h3>
          <div class="pet-stats">
            <div class="stat">
              <span class="icon">❤️</span>
              <div class="progress-bar">
                <div 
                  class="progress" 
                  :style="{ width: pet.health + '%' }"
                  :class="{ low: pet.health < 30 }"
                ></div>
              </div>
            </div>
            
            <div class="stat">
              <span class="icon">🍖</span>
              <div class="progress-bar">
                <div 
                  class="progress" 
                  :style="{ width: pet.hunger + '%' }"
                  :class="{ low: pet.hunger < 30 }"
                ></div>
              </div>
            </div>
            
            <div class="stat">
              <span class="icon">⭐</span>
              <div class="progress-bar">
                <div 
                  class="progress" 
                  :style="{ width: pet.happiness + '%' }"
                  :class="{ low: pet.happiness < 30 }"
                ></div>
              </div>
            </div>
          </div>
          
          <div class="pet-skills">
            <span 
              v-for="skill in pet.skills" 
              :key="skill.id" 
              class="skill-badge"
              :title="skill.description"
            >
              {{ skill.icon }}
            </span>
          </div>
        </div>
        
        <div class="pet-actions">
          <button @click.stop="feedPet(pet)" :disabled="!canFeed(pet)">
            <span class="icon">🍖</span>
          </button>
          <button @click.stop="playWithPet(pet)" :disabled="!canPlay(pet)">
            <span class="icon">🎾</span>
          </button>
          <button @click.stop="trainPet(pet)" :disabled="!canTrain(pet)">
            <span class="icon">📚</span>
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PetList',
  
  props: {
    pets: {
      type: Array,
      required: true
    }
  },

  data() {
    return {
      petIcons: {
        dog: '🐕',
        cat: '🐈',
        rabbit: '🐇'
      }
    }
  },

  methods: {
    getPetIcon(type) {
      return this.petIcons[type] || '🐾';
    },

    getMoodIcon(mood) {
      if (mood >= 80) return '😊';
      if (mood >= 60) return '🙂';
      if (mood >= 40) return '😐';
      if (mood >= 20) return '😟';
      return '😢';
    },

    selectPet(pet) {
      this.$emit('select-pet', pet);
    },

    canFeed(pet) {
      return pet.hunger < 100;
    },

    canPlay(pet) {
      return pet.happiness < 100;
    },

    canTrain(pet) {
      return true; // 可以根据具体逻辑调整
    },

    feedPet(pet) {
      this.$emit('feed-pet', pet.id);
    },

    playWithPet(pet) {
      this.$emit('play-with-pet', pet.id);
    },

    trainPet(pet) {
      this.$emit('train-pet', pet.id);
    }
  }
}
</script>

<style scoped>
.pet-list-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.pet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.add-pet-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #4CAF50;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.add-pet-btn:hover {
  background: #45a049;
  transform: translateY(-2px);
}

.pet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.pet-card {
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: all 0.2s ease;
}

.pet-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.pet-avatar {
  position: relative;
  text-align: center;
  margin-bottom: 12px;
}

.pet-icon {
  font-size: 48px;
}

.mood-indicator {
  position: absolute;
  bottom: -8px;
  right: -8px;
  font-size: 24px;
}

.pet-info h3 {
  margin: 0 0 12px;
  text-align: center;
}

.pet-stats {
  margin-bottom: 16px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: #eee;
  border-radius: 4px;
  overflow: hidden;
}

.progress {
  height: 100%;
  background: #4CAF50;
  transition: width 0.3s ease;
}

.progress.low {
  background: #f44336;
}

.pet-skills {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.skill-badge {
  font-size: 20px;
  padding: 4px;
  background: #f5f5f5;
  border-radius: 4px;
}

.pet-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.pet-actions button {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #f5f5f5;
  cursor: pointer;
  transition: all 0.2s ease;
}

.pet-actions button:hover:not(:disabled) {
  background: #e0e0e0;
  transform: scale(1.1);
}

.pet-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
</style> 